package com.catazy.mvvmlib.navigation

import android.view.View
import androidx.navigation.Navigator
import androidx.navigation.fragment.FragmentNavigator
import androidx.navigation.fragment.NavHostFragment

/**
 * 作者: Tao
 * 日期: 2024/1/30
 * 时间: 10:00
 * 描述:
 */
class RENavHostFragment : NavHostFragment() {

    /**
     * 重写createFragmentNavigator()方法，返回我们自定义的REFragmentNavigator
     */
    override fun createFragmentNavigator(): Navigator<out FragmentNavigator.Destination> {
        return REFragmentNavigator(requireContext(), childFragmentManager, containerId)
    }

    private val containerId: Int
        get() {
            val id = id
            return if (id != 0 && id != View.NO_ID) {
                id
                // Fallback to using our own ID if this Fragment wasn't added via
                // add(containerViewId, Fragment)
            } else androidx.navigation.fragment.R.id.nav_host_fragment_container
        }
}